package com.example.meterialproject.activitys.transition.demo7

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import com.example.meterialproject.R
import kotlinx.android.synthetic.main.fragment_accout_password.*

/**
 *
 * @ClassName: AccountPasswordFragment
 * @Author: android 超级兵
 * @CreateDate: 4/28/22$ 2:31 PM$
 * TODO 账号密码登陆
 */
class AccountPasswordFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        return inflater.inflate(R.layout.fragment_accout_password, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // 账号监听
        editAccountInout.addTextChangedListener {
            if (activity is TransitionDemo7Activity
                && editPwdInout.text.toString().isNotEmpty()
                && it.toString().isNotEmpty()
                && it.toString().length == 11
            ) {
                (activity as TransitionDemo7Activity).takeOverAccount(true,
                    it.toString().trim(),
                    editPwdInout.text.toString().trim())
            } else {
                (activity as TransitionDemo7Activity).takeOverAccount(false, null, null)
            }
        }

        // 密码监听
        editPwdInout.addTextChangedListener {
            if (activity is TransitionDemo7Activity
                && editAccountInout.text.toString().isNotEmpty()
                && it.toString().isNotEmpty()
            ) {
                (activity as TransitionDemo7Activity).takeOverAccount(
                    true,
                    editAccountInout.text.toString().trim(),
                    it.toString().trim(),
                )
            } else {
                (activity as TransitionDemo7Activity).takeOverAccount(false, null, null)
            }
        }
    }
}